﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐 
    //
    // 文件名：BidProductList.cs
    // 文件功能描述：查看采购产品的配送企业，修改配送企业
    // 创建标识：吕海乐2009-04-08
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;


namespace HZ.DrugTrade.Web.Admin.BidProdManage
{
    public partial class BidProductCompany : BasePage
    {
        public BidProductCompany()
        {
            this.ModuleNo = Module.采购产品管理.ToString();
        }

        IBLL_ProcurementBasic ipb = Factory.BLL_ProcurementBasic();
        protected void Page_Load(object sender, EventArgs e)
        {
            //绑定采购产品信息
            if (!IsPostBack)
            {
                string procureCatalogId = Request.QueryString["ProcureCatalogID"];
                HZ.DrugTrade.Model.View.ProcureCatalog procureCatalog = ipb.GetProcureCatalogByID(procureCatalogId);
                if (procureCatalog != null)
                {
                    txtGoodsName.Text = procureCatalog.GoodsName;
                    txtCompany_SC.Text = procureCatalog.CompanyName_SC;
                    txtCompany_TB.Text = procureCatalog.CompanyName_TB;
                    txtProcurePrice.Text = procureCatalog.ProcurePrice.ToString();
                    txtProject.Text = procureCatalog.ProjectName;
                    //txtSortSource.Text = HZ.DrugTrade.Web.Function.FormatDrugSource(procureCatalog.SortSource); 

                    companyId.Value = procureCatalog.CompanyIDs_PS;
                    //companyName.Value = procureCatalog.CompanyNames_PS;
                    hfdCompanyName.Value = procureCatalog.CompanyNames_PS;

                    //将配送企业放入listbox中
                    string companyName = procureCatalog.CompanyNames_PS;
                    string companyID = procureCatalog.CompanyIDs_PS;
                    string[] arrayNames = companyName.Split(',');
                    string[] arrayIds = companyID.Split(',');
                    for (int i = 0; i < arrayNames.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(arrayNames[i]))
                        {
                            ListItem myItem = new ListItem();
                            myItem.Text = arrayNames[i];
                            myItem.Value = arrayIds[i];
                            lstCompanyName.Items.Add(myItem);
                        }
                    }
                }
                else
                {
                    PageError("采购产品不存在！", this.ReturnUrl);
                }
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            ProcureCatalog procureCatalog = new ProcureCatalog();
            procureCatalog.ProcureCatalogID = Request.QueryString["ProcureCatalogID"];
            procureCatalog.CompanyIDs_PS = companyId.Value.TrimEnd(',');
            procureCatalog.CompanyNames_PS = hfdCompanyName.Value.TrimEnd(',');

            if (ipb.UpdateProcureCatalog_CompanyPS(procureCatalog) == 1)
            {
                PageInfo("更新成功！", "BidProductList.aspx");
            }
            else
            {
                PageError("更新失败！", "");
            }
        }
    }
}
